﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DICE_GS;

public class GoEnterRoomButton : MonoBehaviour {
	public GameReadySceneManager sceneManager;
	
	void Start()
	{
		GetComponent<UIButton>().UpdateColor(false, true);
	}
	
	public MapList map;
    void OnClick()
    {
		List<CMapData> mapList = CMapDataManager.Instance.GetMapList();
		if( CSceneManager.isSingleGame )
		{
			if( MyInfo.Instance.MyFriendList.Count == 0)
			{
				LoadingWindow.window.ShowShortLoading();
				RestAPI.singleton.GetMyFriendList(ReturnCallback);
			}
			else
			{
				sceneManager.SelectFriendWindowObject.SetActive(true);
			}
//			SoundManager.Instance.PlaySound(31);
//			sceneManager.ShowBattleMateListWindow();
		}
		else
		{
			CSceneManager.m_mapName = "map_" + mapList[MapListManager.selectedIndex].name;
			CSceneManager.manager.OnCreateJoinButton();
//			CSceneManager c = GameObject.FindObjectOfType(typeof(CSceneManager)) as CSceneManager;
//			LoadingWindow.window.ShowShortLoading();
//			c.GoToEnterroomScene(mapList[MapListManager.selectedIndex].name, null);
		}
    }
	
	void ReturnCallback(Hashtable returnData)
	{
		LoadingWindow.window.HideLoading();
		switch((RestAPIProtocol)returnData["protocol"])
		{
		case RestAPIProtocol.GETMYFRIENDLIST:
			if( MyInfo.Instance.MyFriendList.Count == 0 )
				CSceneManager.manager.GoToEnterroomScene(MainSceneManager.selectedSingleMapName, "");
			else
				sceneManager.SelectFriendWindowObject.SetActive(true);
			break;
		}
	}
}
